package com.tech.connect.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;

import com.ksy.common.dialog.BaseDialog;
import com.ksy.common.dialog.NoticeDialog;
import com.ksy.common.fragment.CommonBaseFragment;
import com.ksy.common.utils.AndroidUtil;
import com.ksy.common.utils.PermissionUtils;
import com.tech.connect.R;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


/**
 * Created by Ksy.
 */

public class BaseFragment extends CommonBaseFragment {

    protected boolean isFullStateBar() {
        return false;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        if (getHeadBar() != null) {
            getHeadBar().setTv_titleColor(R.color.common_colorWhite);
            getHeadBar().setBackgroundResource(R.drawable.icon_headbar);
            if (isFullStateBar()) {
                getHeadBar().setPadding(0, AndroidUtil.dip2px(25), 0, 0);
            }
        }
    }


    protected void showPermissionDialog(final int requestCode, String msg) {
        NoticeDialog noticeDialog = new NoticeDialog(activity);
        noticeDialog.setMsg(msg);
        noticeDialog.setCancelable(false);
        noticeDialog.setOnClickListener(new NoticeDialog.ClickListener() {

            @Override
            public void enter(BaseDialog dialog) {
                dialog.dismiss();
                toSetting(requestCode);
            }
        });
        noticeDialog.show();
    }

    protected void toSetting(int requestCode) {
        PermissionUtils.toAppSetting(BaseFragment.this, requestCode, activity.getPackageName());
    }

    protected void jump2Activity(Class cls) {
        if (cls != null) {
            Intent intent = new Intent(getContext(), cls);
            startActivity(intent);
        }
    }

    protected void jump2Activity(Intent intent) {
        if (intent != null) {
            startActivity(intent);
        }
    }

    protected void jump2Activity(Intent intent, int requestCode) {
        if (intent != null) {
            startActivityForResult(intent, requestCode);
        }
    }

    protected void jump2Activity(Class cls, int requestCode) {
        if (cls != null) {
            Intent intent = new Intent(getContext(), cls);
            startActivityForResult(intent, requestCode);
        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (PermissionUtils.SettingCode == requestCode) {
            onResult4Permission(requestCode);
        }
    }

    protected void onResult4Permission(int requestCode) {

    }

}
